To illustrate the process, in this document several example tables are constructed.
The TABLE tag itself has five optional attributes. The ALIGN attribute controls the location of the table on the page - left, centered or right margin. This does not affect the elements inside the table, it just places the entire table there. The BORDER attribute specifies that a border should be drawn around the table, in the indicated width. If you don't specify a width, it will be a width of one.
The WIDTH attribute, which can take either a percentage or an absolute value in pixels, specifies the width of the table. This can be useful if you want to put multiple tables next to each other. Using an absolute value is not recommended, as it could force a viewer to resize its screen to see the entire table.
CELLSPACING is used to indicate how many pixels there should be between the contents of cells and the border. It takes a value in pixels. The CELLPADDING attribute is used, similarly, to indicate the whitespace in pixels between cells.
The TR element surrounds one row in the table, and can be used to set the horizontal and vertical alignment of all cells in this row. The value specified in TR can be overridden in the individual cells.
A cell can overlap rows or columns. This is indicated with the ROWSPAN and COLSPAN attributes for cells. They indicate how many rows and columns, respectively, this cell will overlap. In the rows or columns after a spanning cell, do not specify this cell again.
The ALIGN attribute is used on the TR element to indicate that all data cells should be right-aligned. The caption will appear at the bottom of the table.
<TABLE BORDER> <CAPTION ALIGN=BOTTOM>Squares</CAPTION> <TR><TH>x <TH>f(x) <TR ALIGN=RIGHT><TD>1 <TD> 1 <TR ALIGN=RIGHT><TD>2 <TD> 4 <TR ALIGN=RIGHT><TD>3 <TD> 9 <TR ALIGN=RIGHT><TD>4 <TD> 16 <TR ALIGN=RIGHT><TD>5 <TD> 25 </TABLE>View it as HTML (requires table support) or as GIF image (1K).
Also, the first cell in the first row is left empty, as the label in this row should go over the second and third cells.
<TABLE BORDER> <TR> <TH><TH COLSPAN=2>Gender <TR> <TH>Age<TH>Male<TH>Female <TR ALIGN=CENTER> <TH>18-24<TD>15%<TD>14% <TR ALIGN=CENTER> <TH>25-30<TD>30%<TD>28% <TR ALIGN=CENTER> <TH>30+<TD>54%<TD>57% </TABLE>View it as HTML (requires table support) or as GIF image (1K).
<TABLE BORDER=10 CELLPADDING=5> <TR><TH>x <TH>f(x) <TR ALIGN=RIGHT><TD> 1 <TD> 1 <TR ALIGN=RIGHT><TD> 2 <TD> 4 <TR ALIGN=RIGHT><TD> 2 <TD> 4 <TR ALIGN=RIGHT><TD> 3 <TD> 9 <TR ALIGN=RIGHT><TD> 4 <TD> 16 <TR ALIGN=RIGHT><TD> 5 <TD> 25 </TABLE>
For a more detailed description of tables, including the formal syntax and what is and isn't permitted inside table cells, see the tables section in the overview of HTML 3.2.
Reference index ~
HTML Basics index ~
Feedback
Copyright © 1996 Arnoud "Galactus" Engelfriet.